#!/usr/bin/perl -wc

package RFCMail::ESMTP::Server::base;

use strict;
use warnings;
use RFCMail::Util::NetEnd;
use RFCMail::Common::Grammar qw(gen_date_time);
use RFCMail::ESMTP::Grammar::Generator qw(encode_extended_domain);


sub data_stamp {
    my ($self, $opts, $maxlen) = @_;
    $opts = $self->{stamp_opts} || ""
	if not defined($opts);
    $maxlen = 78
        if not defined($maxlen);
    my $state = $self->{state};
    my @parts = ("Received: from ".encode_extended_domain($state->{Greeting},
							  $self->{peer_end}->address,
							  $self->{peer_end}->name),
		 "by ".encode_extended_domain($self->{domain},
					      $self->{local_end}->address,
					      $self->{local_end}->name),
		 ($opts !~ /v/ and -S $self->{in_fh} ? "via TCP" : ()),
		 ($opts !~ /w/ ? "with ".$state->{Protocol} : ()),
		 ($opts !~ /i/ and $state->{trans_id} ? "id ".$state->{trans_id} : ()),
		 ($opts !~ /f/ ? ("for", $state->recipients) : ()),
		 ";", gen_date_time(),
		);
    # Wrap-parts-to-lines function follows.
    my @lines;
    my $continuer = "";
    while (@parts) {
	my $line = $continuer . shift(@parts);
	while (@parts) {
	    last if length($line) + length($parts[0]) >= $maxlen;
	    $line .= " ".shift(@parts);
	}
	push @lines, $line;
	$continuer = "\t";
    }
    return (@lines);
}


sub data_start {
    my ($self) = @_;
    $self->{state}->{data_lines} = 0;
    return ([354, "Start mail input; end with <CRLF>.<CRLF>"]);
}


sub data_line {}


sub data_finish { [250, "OK"] }


sub data_commit {}


sub data_abort {}


1;
